<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\relation\BelongsTo;

/**
 * @mixin \think\Model
 */
class AdminStaffDormitoryApply extends Model
{

    public function school(): BelongsTo {
        return $this->belongsTo(AdminSchool::class, 'school_id')
            ->where('is_delete', 0)->bind([
            'school_name' => 'name'
        ]);
    }

    public function staff(): BelongsTo {
        return $this->belongsTo(AdminStaff::class, 'staff_id');
    }

    /*楼栋信息*/
    public function dormitory(): BelongsTo {
        return $this->belongsTo(AdminDormitory::class, 'dormitory_id')
            ->where('is_delete', 0)->bind([
            'dormitory_name' => 'name'
        ]);
    }

    /*宿舍信息*/
    public function student(): BelongsTo {
        return $this->belongsTo(AdminStudentDormitory::class, 'student_dormitory_id')
            ->where('is_delete', 0)->bind([
            'student_dormitory_name' => 'name'
        ]);
    }

    /*楼栋信息*/
    public function oldDormitory(): BelongsTo {
        return $this->belongsTo(AdminDormitory::class, 'old_dormitory_id')
            ->bind([
                'old_dormitory_name' => 'name'
            ]);
    }

    /*宿舍信息*/
    public function oldStudent(): BelongsTo {
        return $this->belongsTo(AdminStudentDormitory::class, 'old_student_dormitory_id')
            ->bind([
                'old_student_dormitory_name' => 'name'
            ]);
    }

    public function getApplyTimeAttr($value,$data)
    {
        if ($data['apply_time'] == 0) {
            return '';
        }
        return date('Y-m-d H:i:s', $data['apply_time']);
    }

}
